<?php
class SysParams extends AppModel {
	var $name = 'SysParams';
	var $useTable = 'sys_params_mst';

	var $primaryKey = 'id';
	var $displayField = 'name';

	function init() {
		$rs = $this->findAll("kbn='tema_id' and deleted is null");
		return $rs;

	}
	function dosave($data) {

		$data['SysParams']['kbn'] = 'tema_id';
		$data['SysParams']['id'] = $this->getMaxId() + 1;
		return $this->save($data);
	}
	function dosavearea($data) {
		$data['SysParams']['kbn'] = 'area_id';
		$data['SysParams']['id'] = $this->getMaxId() + 1;
		$data['SysParams']['name'] = $data['SysParams']['area'];
		return $this->save($data);
	}
	function doDelete($id) {

		return $this->mydelete($id);

	}
	function doDeleteArea($id) {
		return $this->mydeleteArea($id);
	}
	function mydelete($id) {
		$sql = "update sys_params_mst set deleted=now() " .
		"where kbn='tema_id' and id in ($id)";
		$p = $this->query($sql);

	}
	function mydeleteArea($id) {
		$sql = "update sys_params_mst set deleted=now() " .
		"where kbn='area_id' and id in ($id)";
		$p = $this->query($sql);
	}
	function doupdateArea($data) {
		$id = $data['SysParams']['id'];

		$name = $data['SysParams']['area'];
		$description = $data['SysParams']['description'];
		$title = $data['SysParams']['title'];
		$sql = "update sys_params_mst set name = '" .
		$name . "' , description = '" . $description .
		"' , title=' " . $title . "' , modified = now() " .
		"where kbn='area_id' and id = " . $id;

		$p = $this->query($sql);
	}
	function doupdate($data) {

		$id = $data['SysParams']['id'];
		$name = $data['SysParams']['name'];
		$description = $data['SysParams']['description'];
		$title = $data['SysParams']['title'];
		$sql = "update sys_params_mst set name = '" .
		$name . "' , description = '" .
		$description . "' ,  title=' " . $title . "' , modified = now() " .
		"where kbn='tema_id' and id = " . $id;
		$p = $this->query($sql);

	}
	function getMaxId() {
		$sql = "SELECT MAX(id) AS val FROM " .
		$this->useTable;
		$rs = $this->query($sql);
		return $rs[0][0]['val'];
	}

	function getArea() {
		$rs = $this->findAll("kbn='area_id' and deleted is null");
		return $rs;
	}

	function getTema() {
		$rs = $this->findAll("kbn='tema_id' and deleted is null");
		return $rs;
	}
	function getAttentionId($area) {
		$rs = $this->find("kbn='area_id' and deleted is null and \"SysParams\".description = '".$area."'");
		return $rs;
	}	
	function getTemaId($area) {
		$rs = $this->find("kbn='tema_id' and deleted is null and \"SysParams\".description = '".$area."'");
		return $rs;
	}
}
?>
